import { IMenu } from '@/types/systemManage'
import { ref } from 'vue'
import type { FormRules } from 'element-plus'

export default function () {
  const diaFormData = ref<IMenu>({
    path: '',
    name: '',
    component: '',
    meta: {
      title: '',
      icon: ''
    },
    menuId: null,
    parentId: null,
    status: '1',
    menuType: '2',
    order: null
  })
  const diaFormDataRules = ref<FormRules>({
    path: [
      { required: true, message: '请输入路由地址', trigger: 'blur' },
      { pattern: /^\//, message: '路由地址必须以 / 开头', trigger: 'blur' }
    ],
    name: [
      { required: true, message: '请输入菜单名称(英文描述)', trigger: 'blur' },
      { pattern: /^[A-Z][a-zA-Z0-9]*$/, message: '请使用大写字母开头的驼峰命名', trigger: 'blur' }
    ],
    component: [
      { required: true, message: '请输入组件地址', trigger: 'blur' }
    ],
    'meta.title': [
      { required: true, message: '请输入菜单名称', trigger: 'blur' }
    ],
    status: [
      { required: true, message: '菜单状态', trigger: 'change' }
    ],
    parentId: [
      { required: true, message: '选择上级目录', trigger: 'change' }
    ]
  })
  const menuParentTree = ref([])
  return {
    diaFormData, menuParentTree, diaFormDataRules
  }
}
